//console.log('main js loaded'); /* CTA Floating Bar */ var floatingBar = document.querySelector('.ct__cta_floating_bar'); if (floatingBar) { //console.log('floating bar detected'); function checkScroll() { var documentHeight = document.documentElement.scrollHeight; // Get the total height of the document var windowHeight = window.innerHeight; // Get the height of the viewport var scrollableHeight = documentHeight - windowHeight; // Calculate the scrollable area height var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; // Get the current scroll position var scrollPercentage = (scrollTop / scrollableHeight) * 100; // Calculate the percentage of the page scrolled // Show the floating bar if the scroll percentage is at least 40% if (scrollPercentage >= 40) { //console.log('show floating bar'); floatingBar.style.opacity = '1'; floatingBar.style.transform = 'translateY(0)'; } else { //console.log('hide floating bar'); floatingBar.style.opacity = '0'; floatingBar.style.transform = 'translateY(20px)'; } } window.addEventListener('scroll', checkScroll); // Initial check in case the user reloads the page at a scroll position checkScroll(); } else { //console.log('floating bar not found'); } /* Copy to Clipboard */ function copyToClipboard() { var copyText = document.getElementById("textToCopy"); //console.log('Text to copy: ' + copyText); if (copyText) { copyText.select(); copyText.setSelectionRange(0, 99999); // For mobile devices navigator.clipboard.writeText(copyText.value); alert("Copied the text: " + copyText.value); } } /* Modal Handling */ const modal = document.querySelector('.modal'); const disclosureToggle = document.getElementById('disclosure-toggle'); const disclosureToggleInput = document.querySelector('.ct__operator_hero__disclosure-toggle'); function closeModal() { if (disclosureToggle) { disclosureToggle.checked = false; } } if (modal) { document.addEventListener('click', function(event) { if (!modal.contains(event.target) && event.target !== disclosureToggle && event.target !== disclosureToggleInput) { closeModal(); } }); } /* Add Languages next to country flag */ function addCountryNamesToFlags() { const container = document.querySelector('.hreflang-flags-container'); if (!container) { setTimeout(addCountryNamesToFlags, 500); // Retry if the container isn't found yet return; } const links = container.querySelectorAll('a'); links.forEach(link => { const image = link.querySelector('img'); if (image) { const countryName = image.alt; const span = document.createElement('span'); span.textContent = countryName; span.style.marginLeft = '4px'; span.style.fontWeight = 'bold'; link.appendChild(span); } }); } setTimeout(addCountryNamesToFlags, 1000); // Initial call to allow time for flags to load